﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static YJTTool.Core.Global.GlobalMethodEvent;

namespace YJTTool.Core.Global
{
    public class GlobalMethodEvent
    {
        private static GlobalMethodEvent _instance;

        // 私有构造函数，防止外部直接实例化
        private GlobalMethodEvent() { }

        public static GlobalMethodEvent Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new GlobalMethodEvent();
                }
                return _instance;
            }
        }
        public delegate void GlobalMethodEventHandler(GlobalMethodEventParameter v);

        public event GlobalMethodEventHandler OnMessageReceived;

        public void PushMessage(GlobalMethodEventParameter message)
        {
            OnMessageReceived?.Invoke(message); // 触发事件
        }
        public void Subscribe(GlobalMethodEventHandler handler)
        {
            OnMessageReceived += handler;
        }

        public void Unsubscribe(GlobalMethodEventHandler handler)
        {
            OnMessageReceived -= handler;
        }
    }
}
